/**
  @authoer: lss
  @date: 2021/3/5
  @note:
**/
package v1

import (
	"github.com/go-ini/ini"
	"wonlicsys/constPack"
)

type Config struct {
	LogPath string `ini:"LOG_PATH"`
	RunMode string `ini:"RUN_MODE"`
	Host    string `ini:"HOST"`
	Port    string `ini:"PORT"`

	DbHost     string `ini:"DB_HOST"`
	DbUsername string `ini:"DB_USERNAME"`
	DbPassword string `ini:"DB_PASSWORD"`
	DbCharset  string `ini:"DB_CHARSET"`
	DbDataBase string `ini:"DB_DATABASE"`
	DbPort     string `ini:"DB_PORT"`

	RedHost   string `ini:"RED_HOST"`
	RedAuth   string `ini:"RED_AUTH"`
	RedPort   string `ini:"RED_PORT"`
	RedSelect string `ini:"RED_SELECT"`

	//jwt公私钥
	PrivatePemPath string `ini:"PRIVATE_PEM_PATH"`
	PublicPemPath  string `ini:"PUBLIC_PEM_PATH"`

	//钉钉参数
	DingAppKey    string `ini:"DING_APP_KEY"`
	DingAPPSecret string `ini:"DING_APP_SECRET"`
}

var Conf = &Config{}

func InitConf() error {
	//加载启动配置
	conf, err := ini.Load(constPack.BaseConfPath + "app.conf")
	if err != nil {
		const path = "/opt/won-cloud/conf/wonlicsys/" //线上
		conf, err := ini.Load(path + "app.conf")
		if err != nil {
			return err
		}
		err = conf.MapTo(Conf)
		if err != nil {
			return err
		}
		return nil
	}
	err = conf.MapTo(Conf)
	if err != nil {
		return err
	}

	return nil
}
